package com.zhongxi.guoyuan.adapter;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.user.DividendRecorderResult;
import com.zhongxi.guoyuan.utils.DataUtil;

import java.util.List;

import static com.umeng.socialize.utils.DeviceConfig.context;

/**
 * Created by Administrator on 2016/12/9.
 */

public class DividendDetailAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater mLayoutInflater;
    private List<DividendRecorderResult.RecodeCoinRecordDetailResult> list;

    public DividendDetailAdapter(Context context, List<DividendRecorderResult.RecodeCoinRecordDetailResult> data) {
        this.context=context;
        this.mLayoutInflater = LayoutInflater.from(context);
        this.list = data;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.item_recorder, parent, false);
            holder.tvTime = (TextView) convertView.findViewById(R.id.tvTime);
            holder.tvMoney = (TextView) convertView.findViewById(R.id.tvShareAgains);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(null!=list.get(position)){
            DividendRecorderResult.RecodeCoinRecordDetailResult data = list.get(position);

            if(null!=data.getCtime()&&!"".equals(data.getCtime())){
                holder.tvTime.setText(data.getCtime());
            }else{
                holder.tvTime.setText("");
            }
            if (data.getUsetype()==1){
                if(null!=data.getSharesgains()&&!"".equals(data.getSharesgains())){
                    if(null!=data.getSharetype()&&!"".equals(data.getSharetype())){
                        if (data.getSharetype().equals("1")){
                            holder.tvMoney.setText("原始分润"+ DataUtil.formatDataFivePoint(data.getSharesgains())+"元");
                            holder.tvMoney.setTextColor(context.getResources().getColor(R.color.fenrun));
                        }else if (data.getSharetype().equals("2")){
                            holder.tvMoney.setText("合伙分润"+ DataUtil.formatDataFivePoint(data.getSharesgains())+"元");
                            holder.tvMoney.setTextColor(context.getResources().getColor(R.color.postCartItem));
                        }else {
                            holder.tvMoney.setText("分润"+ DataUtil.formatDataFivePoint(data.getSharesgains())+"元");
                            holder.tvMoney.setTextColor(context.getResources().getColor(R.color.fenrun));
                        }
                    }
                }else{
                    holder.tvMoney.setText("分润0元");
                }
                holder.tvTime.setTextColor(context.getResources().getColor(R.color.fenrun));

            }else if (data.getUsetype()==2){
                if(null!=data.getSharesgains()&&!"".equals(data.getSharesgains())){
                    holder.tvMoney.setText("领取"+DataUtil.formatDataFivePoint(data.getSharesgains())+"元");
                }else{
                    holder.tvMoney.setText("领取0元");
                }
                holder.tvTime.setTextColor(Color.RED);
                holder.tvMoney.setTextColor(Color.RED);
            }

        }
        return convertView;
    }
    class ViewHolder{
        private TextView tvTime;
        private TextView tvMoney;
    }
}
